package com.kgdev.cweb.entities.prod.managed;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.kgdev.cweb.entities.ManagedEntity;
import com.kgdev.cweb.entities.prod.owned.client.ClientIdentification;
import com.kgdev.cweb.entities.prod.owned.client.ClientPaymentInfo;
import com.kgdev.cweb.entities.prod.owned.client.ClientShippingInfo;

/**
 * The persistent class for the client database table.
 * 
 */
@Entity
@NamedQueries(value = {
		@NamedQuery(name = "Client.findAll", query = "select c from Client c"),
		@NamedQuery(name = "Client.findById", query = "select c from Client c where c.clientId = :clientId"),
		@NamedQuery(name = "Client.idExists", query = "select count(c) from Client c where c.clientId = :clientId") })
@Table(name = "prod_client")
public class Client implements Serializable, ManagedEntity {
	private static final long serialVersionUID = 1L;

	@Id
	@TableGenerator(name = "PROD_CLN", allocationSize = 1, initialValue = 1, table = "SEQUENCE", valueColumnName = "SEQ_COUNT", pkColumnName = "SEQ_NAME", pkColumnValue = "PROD_CLN")
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "PROD_CLN")
	@Column(name = "email", unique = true, nullable = false)
	private String clientId;

	@Column(name = "client_name", length = 45)
	private String name;

	@Column(name = "person_type", length = 45)
	private String personType;

	@Column(name = "telephone", length = 45)
	private String telephone;

	@Column(name = "is_active", length = 45)
	private Boolean isActive;

	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "email", nullable = false, insertable = false, updatable = false)
	private ClientIdentification identification;

	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name = "client_id")
	private List<ClientPaymentInfo> clientPaymentInfos;

	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name = "client_id")
	private List<ClientShippingInfo> clientShippingInfos;

	@Column(name = "default_lang", length = 45)
	private String defaultLanguage;

	public void setDefaultLanguage(String defaultLanguage) {
		this.defaultLanguage = defaultLanguage;
	}

	public Client() {
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Client other = (Client) obj;
		if (clientId == null) {
			if (other.clientId != null)
				return false;
		} else if (!clientId.equals(other.clientId))
			return false;
		return true;
	}

	public String getClientId() {
		return this.clientId;
	}

	public List<ClientPaymentInfo> getClientPaymentInfos() {
		return clientPaymentInfos;
	}

	public List<ClientShippingInfo> getClientShippingInfos() {
		return clientShippingInfos;
	}

	public ClientIdentification getIdentification() {
		return identification;
	}

	public Boolean getIsActive() {
		return isActive;
	}

	public String getName() {
		return this.name;
	}

	public String getPersonType() {
		return this.personType;
	}

	public String getTelephone() {
		return this.telephone;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((clientId == null) ? 0 : clientId.hashCode());
		return result;
	}

	public void setClientId(String clientId) {
		this.clientId = clientId;
	}

	public void setClientPaymentInfos(List<ClientPaymentInfo> clientPaymentInfos) {
		this.clientPaymentInfos = clientPaymentInfos;
	}

	public void setClientShippingInfos(
			List<ClientShippingInfo> clientShippingInfos) {
		this.clientShippingInfos = clientShippingInfos;
	}

	public void setIdentification(ClientIdentification identification) {
		this.identification = identification;
	}

	public void setIsActive(Boolean isActive) {
		this.isActive = isActive;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setPersonType(String personType) {
		this.personType = personType;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	@Override
	public String toString() {
		return "Client [clientId=" + clientId + ", name=" + name
				+ ", personType=" + personType + ", postalAddress="
				+ ", telephone=" + telephone + "]";
	}

	public String getDefaultLanguage() {
		return defaultLanguage;
	}

}